<?php

namespace apiend\modules\download\controllers;

use Yii;
use apiend\components\Controller;
use apiend\modules\download\models\OrderDeliverySearch;
use apiend\modules\download\models\BookSearch;
use youmbe\phpword\WordDoc;

/**
 * 订单信息相关下载接口
 * 
 * @author emhome <emhome@163.com>
 * @since 2.0
 */
class BookController extends Controller {

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            '*' => ['POST'],
        ];
    }

    /**
     * 待发货订单
     * @inheritdoc
     */
    public function actionIndex() {
        $model = new OrderDeliverySearch();
        $model->store_id = $this->storeId;
        $model->load(Yii::$app->request->post(), '');
        Yii::error([
            Yii::$app->request->post(),
            $model->attributes,
        ]);
        return $model->export();
    }

    /**
     * 财务对账
     * @inheritdoc
     */
    public function actionView() {
        $id = Yii::$app->request->post('id');
        $model = BookSearch::findOne($id);
        WordDoc::widget([
            'asAttachment' => true,
            'fileName' => $model->exportFileName(),
            'model' => $model
        ]);
    }

}
